package com.yuexun.dhdoctor.module.mythings.presenter.impl;



import com.yuexun.dhdoctor.base.BaseEntity;
import com.yuexun.dhdoctor.module.mythings.bean.BackMemberData;
import com.yuexun.dhdoctor.module.mythings.bean.FlowMemberData;
import com.yuexun.dhdoctor.module.mythings.model.IThingModel;
import com.yuexun.dhdoctor.module.mythings.presenter.IFlowPresenter;
import com.yuexun.dhdoctor.module.mythings.ui.view.IFlowView;

import org.kymjs.kjframe.ui.ViewInject;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Administrator on 2017/4/19 0019.
 */

public class FlowPresenter implements IFlowPresenter {

    private IFlowView view;
    private IThingModel model;

    public FlowPresenter(IThingModel model, IFlowView view) {
        this.model = model;
        this.view = view;
    }

    @Override
    public void getFlowMember(Map<String, String> praise) {
        model.getFlowMember(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseEntity<FlowMemberData>>() {

                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("请检查网络状态");
                    }

                    @Override
                    public void onNext(BaseEntity<FlowMemberData> taskPerson) {
                        view.getTaskPerson(taskPerson);
//                        Log.e("jx",taskPerson);
                    }
                });
    }

    @Override
    public void getFlowType(Map<String, String> praise) {
        model.getFlowType(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseEntity<BackMemberData>>() {

                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("请检查网络状态");
                    }

                    @Override
                    public void onNext(BaseEntity<BackMemberData> taskPerson) {
                        view.getFlowType(taskPerson);
                    }
                });
    }
}
